{% extends 'base.html' %}

{% block title %}用户注册{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-6">
        <div class="card shadow-sm">
            <div class="card-header bg-primary text-white">
                <h4 class="mb-0">账号注册</h4>
            </div>
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    <!-- 显示表单错误 -->
                    {% if form.errors %}
                    <div class="alert alert-danger" role="alert">
                        注册失败，请检查以下内容：
                        <ul>
                            {% for field in form %}
                                {% for error in field.errors %}
                                    <li>{{ field.label }}: {{ error }}</li>
                                {% endfor %}
                            {% endfor %}
                        </ul>
                    </div>
                    {% endif %}

                    <!-- 用户名 -->
                    <div class="mb-3">
                        <label for="{{ form.username.id_for_label }}" class="form-label">用户名</label>
                        {{ form.username }}
                        <div class="form-text">3-15个字符，可包含字母、数字和下划线</div>
                    </div>

                    <!-- 密码1 -->
                    <div class="mb-3">
                        <label for="{{ form.password1.id_for_label }}" class="form-label">密码</label>
                        {{ form.password1 }}
                        <div class="form-text">至少8个字符，不能全为数字或过于简单</div>
                    </div>

                    <!-- 密码2 -->
                    <div class="mb-3">
                        <label for="{{ form.password2.id_for_label }}" class="form-label">确认密码</label>
                        {{ form.password2 }}
                        <div class="form-text">请再次输入相同的密码</div>
                    </div>

                    <button type="submit" class="btn btn-primary w-100">注册</button>
                </form>
                <div class="mt-3 text-center">
                    <p>已有账号？<a href="{% url 'login' %}">立即登录</a></p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}